//
//  MenuView.m
//  Molian
//
//  Created by 小蚕科技 on 15/6/1.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "MenuView.h"

@implementation MenuView
- (instancetype)initWithFrame:(CGRect)frame listArray:(NSArray *)arr;
{
    self = [super initWithFrame:frame];
    
    if (self) {
        self.alpha = 0;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickMenuView)];
        [self addGestureRecognizer:tap];
        
        UIImageView *triangleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(DeviceWidth-140+108, 2, 12, 8)];
        triangleImageView.image = [UIImage imageNamed:@"triangleImage"];
        [self addSubview:triangleImageView];
        
        self.blackView = [[UIView alloc] initWithFrame:CGRectMake(DeviceWidth-110, 10, 100, 45*arr.count)];
        self.blackView.backgroundColor = RGBA(86, 86, 86, 0.9);
        self.blackView.layer.cornerRadius = 5;
        [self addSubview:self.blackView];
        if (arr&&arr.count>0) {
            for (int i = 0; i <arr.count; i++) {
                UIButton *listBt = [[UIButton alloc] initWithFrame:CGRectMake(15, 7.5+45*i, 70, 30)];
                [listBt setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
                [listBt setImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
                listBt.titleLabel.font = [UIFont fontWithName:FontName size:15];
                [listBt addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
                listBt.tag = 321+i;
                [listBt setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
                [self.blackView addSubview:listBt];
                
                if (i>0 &&i <arr.count) {
                    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(15, 45*i, 70, 1)];
                    line.backgroundColor = RGBA(255, 255, 255, 0.3);
                    [self.blackView addSubview:line];
                }
            }
        }
        
    }
    
    
    return self;
    
}

- (void)setListTitleArr:(NSArray *)arr
{
    
    for (int i = 0; i<arr.count; i++) {
        UIButton *bt =(UIButton *)[self viewWithTag:i+321];
        [bt setTitle:[arr objectAtIndex:i] forState:UIControlStateNormal];
        self.blackView.frame =CGRectMake(DeviceWidth-110, 10, 100, 45*arr.count);
    }
    
}
- (void)clickMenuView
{
    self.alpha = 0;
}
- (void)clickButton:(UIButton *)bt
{
        [self.delegate clickListButton:bt];
}
- (void)dealloc
{
    self.delegate = nil;
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
